package TestSynchronized;

import org.junit.jupiter.api.Test;

/**
 * @Author Mr.Wen
 * @Version 1.0
 * 可重入锁demo
 */
public class Test1 {
    @Test
    public void test1() {
        Object o = new Object();
        new Thread(() -> {
            synchronized (o) {
                System.out.println("外层");
                synchronized (o) {
                    System.out.println("中层");
                    synchronized (o) {
                        System.out.println("内层");
                    }
                }
            }
        }, "t1").start();
    }


    final Object o = new Object();

    @Test
    public void test2() {
        synchronized (o) {
            m1();
        }
    }

    private void m1() {
        synchronized (o) {
            m2();
            System.out.println("Test1.m1");
        }
    }

    private void m2() {
        synchronized (o) {
            m3();
            System.out.println("Test1.m2");
        }
    }

    private void m3() {
        System.out.println("Test1.m3");
    }


}
